#-*- coding = utf-8 -*-
#@Time : 2022/7/25 22:43
#@Author : BAYERN
#@File : XuanShouBiaoQian.py
#@software: PyCharm

from XuanShouBiaoQianWin import Ui_MainWindow
from PyQt5.QtWidgets import QMessageBox,QMainWindow,QApplication,QCheckBox
import sys

# 选手类
class Player:
    def __init__(self,name,team="未知战队",area="??",tag1="None",tag2="None"):
        self.name = name
        self.team = team
        self.area = area
        self.SaiJi = "未知"
        self.tag1 = tag1
        self.tag2 = tag2
        self.hasTagNumber = 0  # 用于匹配时计算含有多少个标签

    def getInfo(self):
        return "{0:15}{1:8}{2:8}{3:8}{4:8}".format(self.name,self.team,self.area,self.tag1,self.tag2)

    # 检查选手是否有该标签
    # 输入：单个标签  输出：BOOL
    def hasTag(self,tag):
        if tag == self.team or tag == self.tag1 or tag == self.tag2 or tag == self.area:
            return True
        else:
            return False

    # 使标签数清零
    def resetTagNumber(self):
        self.hasTagNumber = 0

class PlayerPool:
    def __init__(self):
        self.playerList = []

    def addPlayer(self,name,team,area,tag1,tag2):
        player = Player(name,team,area,tag1,tag2)
        self.playerList.append(player)

    # 匹配标签
    # 输入：标签列表、匹配标签值(默认为2)
    def getMatchTagPlayers(self,tagList,tagNum=2):
        players = []

        for inputTag in tagList:
            for player in self.playerList: #type: i:Player
                if player.hasTag(inputTag):
                    player.hasTagNumber += 1

        for player in self.playerList:
            if player.hasTagNumber >= tagNum:
                players.append(player)

        # 清零
        for player in self.playerList:
            player.resetTagNumber()

        return players

# 继承UI
class MyWin(QMainWindow,Ui_MainWindow):
    def __init__(self):
        super(MyWin, self).__init__()
        self.setupUi(self)
        self.setWindowTitle("英雄联盟电竞经理选手转会标签匹配查找器V1.0 -- 作者：hjh")
        self.setTrig()
        self.setAction()
        self.setCombox()

    # 绑定按钮事件
    def setTrig(self):
        self.pushButton_ok.clicked.connect(self.clickPushButton_Ok)
        self.pushButton_clear.clicked.connect(self.clickPushButton_clear)

    # 设置菜单
    def setAction(self):
        self.action_about.triggered.connect(self.getAboutAuthorQMessage)
        self.action_instruction.triggered.connect(self.getInstruction)

    # 设定下拉框选项
    def setCombox(self):
        self.comboBox_tagNum.addItems(['1','2','3'])
        self.comboBox_tagNum.setCurrentText('2')

    # 点击确定按钮
    def clickPushButton_Ok(self):
        self.textBrowser.clear()
        tagList = []

        # 遍历
        for i in self.findChildren(QCheckBox): #type: i:QCheckBox
            if i.isChecked():
                tagList.append(i.text())

        tagNum = self.comboBox_tagNum.currentText()
        players = playerPool.getMatchTagPlayers(tagList,int(tagNum))

        # 输出
        self.textBrowser.setText("您所选择的标签为："+str(tagList))
        if len(players) > 0:
            self.textBrowser.append("匹配到的选手为：")
            for player in players:
                self.textBrowser.append(player.getInfo())
        else:
            self.textBrowser.append("未能匹配到选手")

    # 点击清除按钮
    def clickPushButton_clear(self):
        for i in self.findChildren(QCheckBox): #type: i:QCheckBox
            i.setChecked(False)
        self.textBrowser.clear()

    # 跳出关于作者菜单消息框
    def getAboutAuthorQMessage(self):
        QMessageBox.information(self,"联系作者","作者：hjh\n联系方式：471697397@qq.com",QMessageBox.Close)

    # 跳出使用说明消息框
    def getInstruction(self):
        text = "选择若干标签，\n点击确定按钮，\n系统会自动匹配出大于等于匹配标签数（默认为2）的选手"
        QMessageBox.information(self, "使用说明", text, QMessageBox.Close)

#### 主函数####
playerPool = PlayerPool() # 新建选手池
# 新建选手
playerPool.addPlayer("Flandre","EDG","华南","直播天才","#状态")
playerPool.addPlayer("JieJie","EDG","华中","直播天才","大心脏")
playerPool.addPlayer("Scout","EDG","外援", "经验丰富", "操作")
playerPool.addPlayer("Viper","EDG","外援", "上分机器", "操作")
playerPool.addPlayer("Meiko","EDG","西南", "上分机器", "操作")
playerPool.addPlayer("Breathe","RNG","华东", "排位王者", "训练态度")
playerPool.addPlayer("Wei","RNG","华东", "直播天才", "头脑")
playerPool.addPlayer("Xiaohu","RNG","华中", "直播天才", "节目效果")
playerPool.addPlayer("Gala","RNG","华北", "上分机器", "操作")
playerPool.addPlayer("Ming","RNG","华南", "经验丰富", "头脑")
playerPool.addPlayer("Bin","RNG","", "经验丰富", "操作")
playerPool.addPlayer("Wayward","TES","华南", "排位王者", "操作")
playerPool.addPlayer("Tian","TES","东北", "直播天才", "大心脏")
playerPool.addPlayer("Knight","TES","华东", "上分机器", "操作")
playerPool.addPlayer("JackeyLove","TES","华中", "直播天才", "流量")
playerPool.addPlayer("Mark","TES","西南", "经验丰富", "头脑")
playerPool.addPlayer("Rich","V5","外援", "上分机器", "操作")
playerPool.addPlayer("Karsa","V5","华东", "直播天才", "头脑")
playerPool.addPlayer("Rookie","V5","外援", "上分机器", "流量")
playerPool.addPlayer("Photic","V5","华东", "排位王者", "#状态")
playerPool.addPlayer("PPgod","V5","华东", "经验丰富", "流量")
playerPool.addPlayer("Bin","BLG","东北", "经验丰富", "操作")
playerPool.addPlayer("Crisp","BLG","华中", "经验丰富", "头脑")
playerPool.addPlayer("Tarzan","LNG","外援", "经验丰富", "头脑")
playerPool.addPlayer("Doinb","LNG","外援", "直播天才", "流量")
playerPool.addPlayer("Light","LNG","华东", "排位王者", "操作")
playerPool.addPlayer("369","JDG","华中", "直播天才", "#状态")
playerPool.addPlayer("Kanavi","JDG","外援", "上分机器", "#状态")
playerPool.addPlayer("Missing","JDG","华东", "上分机器", "操作")
playerPool.addPlayer("Lwx","FPX","华东", "直播天才", "节目效果")
playerPool.addPlayer("Theshy","WBG","外援", "直播天才", "流量")
playerPool.addPlayer("Angel","WBG","华南", "直播天才", "大心脏")
playerPool.addPlayer("Cube","RA","华中", "经验丰富", "节目效果")



if __name__ == '__main__':
    app = QApplication(sys.argv)
    myWin = MyWin()
    myWin.show()
    sys.exit(app.exec_())